package com.qf.question.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qf.common.R;
import com.qf.question.entity.Question;
import com.qf.question.entity.QuestionCategory;
import com.qf.question.mapper.QuestionCategoryMapper;
import com.qf.question.mapper.QuestionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Daniel
 * @since 2021-10-12
 */
@RestController
@RequestMapping("/bank_service/question-category")
public class QuestionCategoryController {
    @Autowired
    QuestionCategoryMapper questionCategoryMapper;
    @Autowired
    QuestionMapper questionMapper;


    /**
     * 根据问题类型查询问题
     * @param type
     * @return
     */
    @GetMapping("/findQuestionByType")
    public R findQuestionByType(@RequestParam String type){
        QueryWrapper<QuestionCategory> queryWrapper = new QueryWrapper<>();

        QueryWrapper<QuestionCategory> uk_kname = queryWrapper.eq("uk_kname", type);
        QuestionCategory questionCategory = questionCategoryMapper.selectOne(uk_kname);

        Integer pkKid1 = questionCategory.getPkKid();
        QueryWrapper<Question> questionWrapper = new QueryWrapper<>();
        QueryWrapper<Question> statements = questionWrapper.eq("kid", pkKid1);
        List<Question> questions = questionMapper.selectList(statements);
        System.out.println("最终结果："+questions);

        return R.ok();
    }


    /**
     * 查询所有问题类型
     * @return
     */
    @GetMapping
    public R showAll(){
        List<QuestionCategory> questions = questionCategoryMapper.selectList(null);
        if (questions!=null){
            System.out.println("最终结果："+ questions);
            return R.ok();
        }
        return R.error();
    }

}

